package com.dys.testdatetime13;

import java.time.LocalDateTime;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAdjusters;

/**
 * @className: com.dys.testdatetime13.TemporalAdjusterTest
 * @description: TemporalAdjuster时间校正器
 * @author: pine cone
 * @version: v1.0.0
 * @createTime: 2024/09/03 下午10:28
 */
public class TemporalAdjusterTest {

    /**
     * 这是一个main()方法,是应用程序的入口
     *
     * @param args 方法的形参列表,是一个字符串数组,包含了从命令行传递给程序的参数
     */
    public static void main(String[] args) {
        // 1.获取当前日期时间
        LocalDateTime now = LocalDateTime.now();
        // 将当前日期时间调整为下个月的1号
        TemporalAdjuster adjuster = (temporal) -> {
            LocalDateTime dateTime = (LocalDateTime) temporal;
            LocalDateTime nextMonth = dateTime.plusMonths(1).withDayOfMonth(1);
            System.out.println("Next month: " + nextMonth);
            return nextMonth;
        };

        // LocalDateTime nextMonth = now.with(adjuster);
        LocalDateTime nextMonth = now.with(TemporalAdjusters.firstDayOfNextMonth());
        System.out.println("下个月：" + nextMonth);
    }
}
